﻿using furion.blog.Application.Contracts;
using furion.blog.Domain.Query.AreaCode;
using furion.blog.Domain.Shared.Attribute;
using furion.blog.Domain.Shared.Enum;
using furion.blog.Utils;
using Furion.DynamicApiController;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace furion.blog.Web.Entry.Api
{
    /// <summary>
    /// 图片操作类
    /// </summary>
    [ApiDescriptionSettings(Groups = new string[] { "CommonApi" })]
    [Route("api/common")]
    public class CommonApiController : IDynamicApiController
    {
        private readonly ILocationService _locationService;
        private readonly IAreaCodeService _areaCodeService;

        public CommonApiController(ILocationService locationService, IAreaCodeService areaCodeService)
        {
            this._locationService = locationService;
            this._areaCodeService = areaCodeService;
        }

        [ActionAttribute(Name = "性别选项接口", Desc = "获取性别选项")]
        [HttpGet, Route("sex"), AllowAnonymous]
        public async Task<IActionResult> sex()
        {
            var ret = await furion.blog.Domain.Shared.Enum.Sex.Items();
            return new OkObjectResult(ResultUtil.Success(ret));
        }

        [ActionAttribute(Name = "微信接口选项接口", Desc = "获取系统调用微信接口的选项")]
        [HttpGet, Route("wechat/api/request/options"), AllowAnonymous]
        public async Task<IActionResult> wechatApiRequestOptions() {
            return new OkObjectResult(ResultUtil.Success(await WxRequestApi.Items()));
        }


        /// <summary>
        /// 通过经维度获取位置信息
        /// </summary>
        /// <param name="lat">维度</param>
        /// <param name="lng">经度</param>
        /// <returns></returns>
        [ActionAttribute(Name = "通过经维度获取位置信息接口", Desc = "通过经维度获取位置信息(调用百度开放接口)")]
        [HttpGet, Route("location"),AllowAnonymous]
        public async Task<IActionResult> location([FromQuery(Name = "lat")]string lat,[FromQuery(Name = "lng")]string lng) {
            var ret = await this._locationService.Info(lat,lng);
            return new OkObjectResult(ResultUtil.Success(ret));
        }


        [ActionAttribute(Name = "获取地区接口", Desc = "获取地区信息")]
        [HttpGet, Route("areaCode")]
        public async Task<IActionResult> areaCode([FromQuery] AreaCodeDetailQuery query)
        {
            var ret = await this._areaCodeService.All(query);
            return new OkObjectResult(ResultUtil.Success(ret));
        }

        [ActionAttribute(Name = "获取楼盘图片类型接口", Desc = "获取楼盘图片类型")]
        [HttpGet, Route("building/photo/category")]
        public async Task<IActionResult> buildingPhotoCategory()
        {
            var ret = await BuildingPhotoCategory.Items();
            return new OkObjectResult(ResultUtil.Success(ret));
        }

    }
}
